﻿using AutoMapper;
using MediatR;
using ProcurementManagement.Applcation.Command.VendorCommand;
using ProcurementManagement.Infrstructre.Interface;
using System.Security.Claims;

namespace ProcurementManagement.Applcation.CommandHanlers.VendorCommandHanlers
{
    public class VendorDelCommandHandlers : IRequestHandler<VendorDelCommand, int>
    {
        protected readonly InterfaceVendorRepository repository;
        protected readonly IMapper mapper;
        public VendorDelCommandHandlers(InterfaceVendorRepository repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<int> Handle(VendorDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await repository.GetAll()).Where(c => request.AllocateId.Contains(c.VendorId)).ToList();
           
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await repository.UpdataAsync(item);
            }
            return 1;
        }
    }
}
